﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Zero.UControl.Component.Command
{
    public class BaseCommand<T> : ICommand
    {
        public Func<T, bool> CanExecuteAction;
        public Action<T> ExecuteAction;

        public event EventHandler? CanExecuteChanged;

        public BaseCommand(Action<T> executeAction, Func<T, bool> canExecuteAction = null)
        {
            ExecuteAction = executeAction;
            CanExecuteAction = canExecuteAction;
        }

        public bool CanExecute(object? parameter)
        {
            return CanExecuteAction == null || CanExecuteAction.Invoke((T)parameter);
        }

        public void Execute(object? parameter)
        {
            ExecuteAction?.Invoke((T)parameter);
        }
    }
}
